<!--企业安全环保基本信息表 compan-->
<template>
    <Layout>
        <Form ref="queryForm" :model="dataToQuery" :label-width="120">
            <Row class="query-form" >
                <Col span="8">
                  <FormItem label="二级集团：">
                    <two-level-org org-code v-model="dataToQuery.twoLevelOrgId" ></two-level-org>
                  </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label='企业名称：'>
                      <company-select v-model="dataToQuery.companyName"></company-select>
<!--                      <cascaderDom   class="query-form-el" ref="groupOrg1" style="margin-top:5px;width: 100%;"-->
<!--                                       @setOrgInfo='setOrgId'-->
<!--                                       @setOrgname='setOrgName'-->
<!--                                       :orgTree="true" ></cascaderDom>-->
                    </FormItem>
                </Col>
                <Col span="8" v-if="!switchFlag">
                    <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                    <Button @click="reseter" class="ivu-btn-reset"  >重置</Button>
                    <Button type="primary" class="ivu-btn-query"   icon="md-search"  @click="query">查询</Button>
                </Col>
              <Col span="8" v-else>
                <FormItem label='项目状态：'>
                  <Select v-model='dataToQuery.projectStart' @on-change="()=>this.query()" class='query-form-el'>
                    <Option value="0">建设中</Option>
                    <Option value="1">已竣工</Option>
                  </Select>
                </FormItem>
              </Col>
            </Row>
            <Row  v-show="switchFlag" class="query-form" >
              <Col span="8" >
                <FormItem label='建设项目名称：'>
                  <Input  class='' type='text' v-model='dataToQuery.projectName'></Input>
                </FormItem>
              </Col>
                <Col span="16">
                  <div style="float: right;">
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reseter" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                  </div>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large"  class="ivu-btn-add" icon="md-add"  @click="addInfo">新增</Button>
                    <Button type="primary" class="ivu-btn-add"   icon="md-cloud-download"  @click="downloadFile" :loading="exportLoading">导出</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' :height="tableHeight"  no-data-text="没有查询到相关数据!" @on-selection-change = 'getSelectRows' :loading='pageStatus.loading ||  pageStatus.baseLoading' @on-sort-change="querySort"
               border :columns="columns1"  :data="dataTable" show-summary :summary-method="handleSummary" sum-text="合计">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24" >
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange1" @on-page-size-change="pageSizeChange1" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </Col>
        </Row>
        <Modal  :title="mode == 'view' ?'地产工程建设表详情':'地产工程建设表'" :transfer=false :mask-closable="false" v-model="dialogShow" v-if="dataToView && dialogShow" :width=800 :styles="{height:'559px'}"  class-name='limit-height-dialog'>
            <Row>
                <Col span="24">
                    <Form ref="dataToView" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false" :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"  :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?160:null">
                        <Row type="flex" justify="space-around" class="code-row-bg">

                            <Col span="11">
                                <FormItem label='绩效考核责任书编号：' prop='parNum'>
                                    <div v-if="mode === 'view'">{{ dataToView.parNum }}</div>
                                    <Input v-else class=''placeholder="请填写绩效考核责任书编号" type='text' v-model='dataToView.parNum'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='建设项目名称：' prop='projectName'>
                                    <div v-if="mode === 'view'">{{ dataToView.projectName }}</div>
                                    <Input v-else class=''placeholder="请填写建设项目名称" type='text' v-model='dataToView.projectName'></Input>
                                </FormItem>
                            </Col>

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='企业名称：' prop='companyName'>
                                    <div v-if="mode === 'view'">{{ dataToView.companyName }}</div>
                                    <!--    <Input v-else class=''placeholder="请选择企业名称" type='text' v-model='dataToView.companyName' :readonly="true" @on-focus="openSelect"></Input>-->
                                    <cascaderDom v-else  class="query-form-el" ref="groupOrg"
                                                 @setOrgInfo='(data)=>{cascaderDomIdChangeHandle(data,"companyId");}'
                                                 @setOrgname='(data)=>{cascaderDomNameChangeHandle(data,"companyName");}'
                                                 :currentOrgId = "dataToView.companyId"
                                                 :setCurrentName="{label:dataToView.companyName, value:dataToView.companyId}"
                                                 :orgTree="true" ></cascaderDom>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='归属地区：' prop='locationId'>
                                    <!--       <div v-if="mode === 'view'">{{ dataToView.attriErea }}</div>
                                           <Input v-else class=''placeholder="请填写归属地区" type='text' v-model='dataToView.attriErea'></Input>-->
                                    <div v-if="mode === 'view'">{{areaCodeToAreaName(dataToView.locationId)}}</div>
                                    <Cascader v-else :data="tempAreaTree" v-model="dataToView.attriEreaArr" change-on-select :transfer="true"
                                              :load-data="areaTreeLoadData" :render-format="labels=>labels.join('·')"  :clearable='false'
                                              @on-change="(value,selectedData)=>{$set(dataToView,'locationId',value.join(','))}"></Cascader>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='建设面积(平方米)：' prop='area'>
                                    <div v-if="mode === 'view'">{{ dataToView.area }}</div>
                                    <InputNumber v-else class='w'placeholder="请填写建设面积(平方米)" min="0" type='text' v-model='dataToView.area'></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='施工周期：' prop='construction'>
                                    <div v-if="mode === 'view'">{{renderViewDates(dataToView.startDate,dataToView.endDate)  }}</div>
                                    <DatePicker v-else class="w" placeholder="请选择施工周期" v-model='construction' type="daterange" placement="bottom-end" editable="false"></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='工人数量：' prop='worker'>
                                    <div v-if="mode === 'view'">{{ dataToView.worker }}</div>
                                    <InputNumber v-else class='w'placeholder="请填写工人数量" min="0" type='text' v-model='dataToView.worker'></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='管理人员数量：' prop='management'>
                                    <div v-if="mode === 'view'">{{ dataToView.management }}</div>
                                    <InputNumber v-else class='w'placeholder="请填写管理人员数量" min="0" type='text' v-model='dataToView.management'></InputNumber>
                                </FormItem>
                            </Col>

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='承建单位：' prop='contractor'>
                                    <div v-if="mode === 'view'">{{ dataToView.contractor }}</div>
                                    <Input v-else class=''placeholder="请填写承建单位" type='text' v-model='dataToView.contractor'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='承建单位作业资质等级：' prop='gradeId'>
                                    <div v-if="mode === 'view'">{{ dataToView.gradeName }}</div>
<!--                                    <Input v-else class=''placeholder="请填写承建单位作业资质等级" type='text' v-model='dataToView.gradeName'></Input>-->
                                    <Select v-else v-model="dataToView.gradeId" @on-change="selectstdGrade"
                                            :label-in-value="true" placeholder="请选择承建单位作业资质等级">
                                        <Option v-for="item in grades" :value="item.codingCodeId"
                                                :key="item.codingCodeId">{{ item.codingName }}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='发证机关：' prop='issuingAuthority'>
                                    <div v-if="mode === 'view'">{{ dataToView.issuingAuthority }}</div>
                                    <Input v-else class=''placeholder="请填写发证机关" type='text' v-model='dataToView.issuingAuthority'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11" >
                                <FormItem label='有效期：' prop='effectiveDate'>
                                    <div v-if="mode === 'view'">{{ renderViewDate(dataToView.effectiveDate) }}</div>
                                    <DatePicker v-else class="w" placeholder="请选择有效期" v-model='dataToView.effectiveDate' ></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='形象进度描述：'>
                                    <div v-if="mode === 'view'">{{ dataToView.proDesc }}</div>
                                    <Input v-else class=''placeholder="请填写形象进度描述" type='textarea' v-model='dataToView.proDesc'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='现场教育培训及交底情况：' >
                                    <div v-if="mode === 'view'">{{ dataToView.disclosure }}</div>
                                    <Input v-else class=''placeholder="请填写现场教育培训及交底情况" type='textarea' v-model='dataToView.disclosure'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='现场设备设施检修情况：'>
                                    <div v-if="mode === 'view'">{{ dataToView.maintenance }}</div>
                                    <Input v-else class=''placeholder="请填写现场设备设施检修情况" type='textarea' v-model='dataToView.maintenance'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='月度主要风险点：'>
                                    <div v-if="mode === 'view'">{{ dataToView.riskPoints }}</div>
                                    <Input v-else class=''placeholder="请填写月度主要风险点" type='textarea' v-model='dataToView.riskPoints'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='管控措施：' >
                                    <div v-if="mode === 'view'">{{ dataToView.measures }}</div>
                                    <Input v-else class=''placeholder="请填写管控措施" type='textarea' v-model='dataToView.measures'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='环保安全消防“三同时”手续办理情况：' >
                                    <div v-if="mode === 'view'">{{ dataToView.handlingSituation }}</div>
                                    <Input v-else class=''placeholder="请填写环保安全消防“三同时”手续办理情况" type='textarea' v-model='dataToView.handlingSituation'></Input>
                                </FormItem>
                            </Col>
                        </Row>
						<Row type="flex" justify="space-around" class="code-row-bg">
							<Col span="11">
							<FormItem label='填报人：' prop='registrant'>
								<div v-if="mode === 'view'">{{dataToView.createUserName}}</div>
								<Input v-if="mode === 'add'" type='text' v-model='dataToView.registrant' readonly></Input>
								<Input v-if="mode === 'edit'" type='text' v-model='dataToView.createUserName' readonly></Input>
							</FormItem>
							</Col>
							<Col span="11">
							<FormItem label='填报时间：' prop='registTime'>
								<div v-if="mode === 'view'">{{renderViewDate(dataToView.createDate)}}</div>
								<DatePicker v-if="mode === 'add'" type="date" placeholder="请选择日期" class="w" v-model='dataToView.registTime'
									readonly></DatePicker>
								<DatePicker v-if="mode === 'edit'" type="date" placeholder="请选择日期" class="w" v-model='dataToView.createDate'
									readonly></DatePicker>
							</FormItem>
							</Col>
						</Row>
						<Row type="flex" justify="space-around" class="code-row-bg">
							<Col span="11">
							<FormItem label='填报人电话：' prop='createMobile'>
								<div v-if="mode === 'view'">{{dataToView.createMobile}}</div>
								<Input v-if="mode === 'add'" type='text' v-model='dataToView.createMobile'></Input>
								<Input v-if="mode === 'edit'" type='text' v-model='dataToView.createMobile' :readonly="this.currentUser.userId === dataToView.createUserId ? false : 'readonly'"></Input>
							</FormItem>
							</Col>
							<Col span="11">
							</Col>
						</Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-save' @click="submit('dataToView')" >确定</Button>
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
                <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
    import {Api} from '@/api/index.js'
    import {sessionStorage} from '@/common/cacheUtils.js';
    import {formatDate} from '@/tools/index'
    import _deepclone from 'lodash/cloneDeep'
    import { mapState, mapGetters, mapActions } from 'vuex'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import pageCommonFunction from '@/components/pageCommonFunction.js'
    export default {
        components:{
            cascaderDom
        },
        computed:{
            ...mapState('trhg', {
                areaMap: state => state.area.areaMap?state.area.areaMap:[],
                areaTreeMap: state => state.area.areaTreeMap?state.area.areaTreeMap:{},
            }),
        },
        data(){
            return {
                ...this.createCommonDataField(),
                switchFlag:false,
                construction:[null,null],
                columns1: [
                    { title: '序号', minWidth: 80, key:'index', fixed: 'left', align: 'center', render: this.indexColumnsRenderSum},
                    { fixed: 'left',title: '项目状态',  align: 'center',minWidth:100 ,render: (h, params) => {
                            if (!params.row.endDate){
                                return "建设中"
                            }
                            return h('span',(new Date(params.row.endDate)<=new Date())?'已竣工':'建设中' )
                        }
                    },
                    { key:'parNum',fixed: 'left',title: '绩效考核责任书编号',  align: 'center',minWidth:100 },
                    { key:'companyName',fixed: 'left',title: '企业名称',  align: 'center',minWidth:150 },
                    { key:'locationId',title: '所在地',  align: 'center' ,minWidth:150, render: (h, params) =>{ return h('span', this.areaCodeToAreaName(params.row.locationId));}},
                    { key:'projectName',title: '建设项目名称',  align: 'center',minWidth:150 },
                    { key:'area',title: '建设面积(平方米)',  align: 'center',minWidth:120 },
                    { key:'construction',title: '施工周期',  align: 'center' ,minWidth:150, render: (h, params) => {
                        if (!(params.row.startDate||params.row.endDate)){
                            return ""
                        }
                            let startDate = new Date(params.row.startDate);
                            let endDate = new Date(params.row.endDate);
                            return h('span', startDate.getFullYear() + '/' + (startDate.getMonth() + 1) + '/' + startDate.getDate() + ' ~ ' +
                                endDate.getFullYear() + '/' + (endDate.getMonth() + 1) + '/' + endDate.getDate())
                        }
                    },
                    { key:'proDesc',title: '形象进度描述',  align: 'center',minWidth:150 ,ellipsis: true,tooltip:true},
                    { key:'management',title: '管理人员数量',  align: 'center',minWidth:90 },
                    { key:'worker',title: '工人数量',  align: 'center' ,minWidth:90},
                    { key:'disclosure',title: '现场教育培训及交底情况',  align: 'center', ellipsis: true,minWidth:150,tooltip:true},
                    { key:'maintenance',title: '现场设备设施检修情况',  align: 'center', ellipsis: true,minWidth:150,tooltip:true},
                    { key:'riskPoints',title: '月度主要风险点',  align: 'center', ellipsis: true,minWidth:150,tooltip:true},
                    { key:'measures',title: '管控措施',  align: 'center', ellipsis: true,minWidth:150,tooltip:true},
                    { key:'handlingSituation',title: '环保安全消防“三同时”手续办理情况',  align: 'center', ellipsis: true,minWidth:150,tooltip:true},
                    { key:'contractor',title: '承建单位',  align: 'center',minWidth:150 },
                    { key:'gradeName',title: '承建单位作业资质等级',  align: 'center',minWidth:100 },
                    { key:'issuingAuthority',title: '发证机关',  align: 'center',minWidth:150 },
                    { key:'effectiveDate',title: '有效期',  align: 'center',minWidth:120,render:this.renderCellDate, sortable: 'custom' },
                    { key:'updateDate',title: '更新时间',  align: 'center',minWidth:120,render:this.renderCellDate, sortable: 'custom' },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 200,
                        align: 'center',
                        render: (h, params) => {
                          if(params.row.id == -1){
                            return;
                          }
							            if (this.currentUser.loginId === this.Common.admin || this.currentUser.userId === params.row.createUserId  || this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                                ||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined) {
                                return h('div', [
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        style: {fontSize: '14px',},
                                        on: {
                                            click: () => {
                                                this.viewData(params);
                                            }
                                        }
                                    }, '详情'),
                                    h('Divider', {props: {type: 'vertical'}}, ''),
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        disabled: true,
                                        style: {fontSize: '14px'},
                                        on: {
                                            click: () => {
                                                this.showData(params);
                                            }
                                        }
                                    }, '修改'),
                                    h('Divider', {props: {type: 'vertical'}}, ''),
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        style: {fontSize: '14px', color: 'red'},
                                        on: {
                                            click: () => {
                                                this.deleteData(params);
                                            }
                                        }
                                    }, '删除')
                                ]);
                            } else {
                                return h('div', [
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        style: {fontSize: '14px',},
                                        on: {
                                            click: () => {
                                                this.viewData(params);
                                            }
                                        }
                                    }, '详情'),
                                    h('Divider', {props: {type: 'vertical'}}, ''),
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        style: {fontSize: '14px', color: '#c5c8ce'}
                                    }, '修改'),
                                    h('Divider', {props: {type: 'vertical'}}, ''),
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        style: {fontSize: '14px', color: '#c5c8ce'}
                                    }, '删除')
                                ]);
                            }
                        }
                    }
                ],
                ruleCustom : {
                    parNum: [ { required: true, message: '请填写绩效考核责任书编号', trigger: 'change',}],
                    companyName: [ { required: true, message: '请填写企业名称', trigger: 'change',}],
                    locationId: [ { required: true, message: '请填写所在地', trigger: 'change',}],
                    projectName: [ { required: true, message: '请填写建设项目名称', trigger: 'change',}],
                    area: [ { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, required: true, message: '请填写建筑面积(平方米)', trigger: 'change',type:'number'}],
                    construction: [{
                        validator: (rule, value, callback) => {
                            console.log(this.construction);
                            if (this.construction[0] == null || this.construction[1] == null) {
                                callback(' ')
                            }if (this.construction[0] == '' || this.construction[1] == '') {
                                callback(' ')
                            }  else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    proDesc: [ { required: true, message: '请填写形象进度描述', trigger: 'change',}],
                    management:  [ { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, required: true, message: '请填写管理人员数量', trigger: 'change',type:'number'}],
                    worker: [ { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, required: true, message: '请填写工人数量', trigger: 'change',type:'number'}],
                    disclosure: [ { required: true, message: '请填写现场教育培训及交底情况', trigger: 'change',}],
                    maintenance: [ { required: true, message: '请填写现场设备设施检修情况', trigger: 'change',}],
                    riskPoints: [ { required: true, message: '请填写月度主要风险点', trigger: 'change',}],
                    measures: [ { required: true, message: '请填写管控措施', trigger: 'change',}],
                    handlingSituation: [ { required: true, message: '请填写环保安全消防“三同时”手续办理情况', trigger: 'change',}],
                    contractor: [ { required: true, message: '请填写承建单位', trigger: 'change',}],
                    gradeId: [ { required: true, message: '请填写承建单位作业资质等级', trigger: 'change',}],
                    issuingAuthority: [ { required: true, message: '请填写发证机关', trigger: 'change',}],
                    effectiveDate: [ { required: true, message: '请填写有效期', trigger: 'change',type:'date'}],
					createMobile: [{ pattern: /^((0\d{2,3}-\d{7,8})|(1[3675849]\d{9}))$/, required: true, message: '请填写填报人电话', trigger: 'change' }],
                },
                tableHeight:10,
                industryList:[],
                safeLevelList:[],
                twoOrgInfo:[],
                // api
                standardSelectModal:false,
                queryUrl:Api.queryConstructionProject,
                deleteUrl:Api.deleteConstructionProject,
                updateUrl:Api.updateConstructionProject,
                saveUrl:Api.saveConstructionProject,
            }
        },
        async mounted() {
            this.dataToQuery ={ projectStart:'0'};
            this.setSumTableHeight();
            this.pageStatus.baseLoading = true;
            await this.$store.dispatch('trhg/area/query', {scope:this}, { root: true });
            this.pageStatus.baseLoading = false;
            this.$http.get(Api.queryCodeDetailBySortId + '/GRADE-000001', {params: {}}).then((res) => {
                this.grades = res.data.data;
            });
            this.query();
            this.tempAreaTree = this.areaTreeMap['0']
        },
        methods:{

            ...pageCommonFunction,
            async showData(data) {
                if (this.beforeEditDialogOpen instanceof Function) {
                    await this.beforeEditDialogOpen(data)
                }
                //修改页面
                this.mode = 'edit'
                let dataToView = _deepclone(data.row);
                this.dataToView = dataToView;
                this.construction = [new Date(data.row.startDate),new Date(data.row.endDate)];
                this.dataToView.registTime = new Date();
                if (this.afterDataToViewInit instanceof Function) {
                    await this.afterDataToViewInit(dataToView)
                }
                this.dialogShow = true;
                setTimeout(()=>{
                    this.dialogVisibleChangeHandele(this.dialogShow)
                },100)
            },
            renderViewDates(startDate,endDate) {
                if (!(startDate||endDate)){
                    return ""
                }
                let contractTermStart = new Date(startDate);
                contractTermStart = contractTermStart.getFullYear() + '-' + (contractTermStart.getMonth() + 1) + '-' + contractTermStart.getDate()
                let contractTermEnd = new Date(endDate);
                contractTermEnd = contractTermEnd.getFullYear() + '-' + (contractTermEnd.getMonth() + 1) + '-' + contractTermEnd.getDate()
                return  contractTermStart + '至' + contractTermEnd
            },
            beforeEditDialogOpen(data) {
                if(data.row.locationId){
                    data.row.attriEreaArr = data.row.locationId.split(',')
                    data.row.companyAddressName = this.areaCodeToAreaName(data.row.locationId)
                }
            },
            async afterDataToViewInit(data) {
                if (data && data.locationId) {
                    let companyAddressArr = data.locationId.split(',')
                    this.tempAreaTree = []
                    setTimeout(() => {
                        this.tempAreaTree = this.addressEditArr(this.areaTreeMap,companyAddressArr)
                    }, 100)
                }
            },
            deleteData(params) {
                this.deleteDateById(params.row.id);
            },
            switchQuery(flag) {
                this.switchFlag = flag;
                if (!this.switchFlag) {
                    this.tableHeight = this.tableHeight + 44;

                } else {
                    this.tableHeight = this.tableHeight - 44;
                }

            },
            setOrgId(data) {
                this.dataToQuery.companyId = data[data.length - 1];
            },
            setOrgName(data) {

            },
            query() {
                this.query1()
            },
            selectSafeLevel(row){
                this.dataToView.safeLevelId = row.value;
                this.dataToView.safeLevel= row.label;
            },
            selectstdGrade(stdRank) {
                this.dataToView.gradeId = stdRank.value;
                this.dataToView.gradeName= stdRank.label;
            },
            selectstdIndustry(row){
                this.dataToView.industryId = row.value;
                this.dataToView.industry= row.label;
            },
            renderCellDateAndDate(h, params) {
                if (!(params.row.startDate||params.row.endDate)){
                    return ""
                }
                return h('span', formatDate(new Date(params.row.startDate), "yyyy-MM-dd")+"~"+formatDate(new Date(params.row.endDate), "yyyy-MM-dd"))
            },
            submit(name) {
                let att = this.areaCodeToAreaName(this.dataToView.locationId);
                this.dataToView.locationName = att;
                if (this.construction.length == 2){
                    this.dataToView.startDate = formatDate(new Date(this.construction[0]), "yyyy-MM-dd");
                    this.dataToView.endDate = formatDate(new Date(this.construction[1]), "yyyy-MM-dd");
                }
                this.submitBase(name);
            },
            addInfo() {
                this.dataToView = (this.createEmptyDataToAdd instanceof Function) ? this.createEmptyDataToAdd() : {};
                this.dataToView.registrant = this.currentUser.userName;
                this.dataToView.registTime = new Date();
                this.mode = 'add';
                this.dialogShow = true;
            },
            createEmptyDataToAdd() {
                this.construction = [null,null];
                return{
                    companyId:sessionStorage('userId').getObject('userId').companyId,
                    companyName:sessionStorage('userId').getObject('userId').companyName,
                    worker:0,
                    management:0,
                    area:0,
					createMobile: sessionStorage('userId').getObject('userId').mobileNumber
                }
            },
            reseter() {
                this.safeRanks = [];
                this.safeLevels = [];
                this.dataToQuery = {
                    projectStart:'0'
                };
                // this.$refs.groupOrg1.resetCurrentOrg();
                this.query1()
            },
            downloadFile() {
                let orgId = sessionStorage('userId').getObject('userId').companyId
                let data = {
                    orgId: orgId,
                };
                data = Object.assign(data, JSON.parse(JSON.stringify(this.dataToQuery)));
                this.exportLoading = true;
                this.$http.get(Api.queryConstructionProject + '/download', {
                    params:data,
                    responseType: 'blob'      //告诉服务器我们需要的响应格式
                }).then((res) => {
                  this.exportLoading = false;
                  const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
                    });
                    aLink.href = URL.createObjectURL(blob)
                    aLink.download = "地产工程建设("+ formatDate(new Date(), "yyyy-MM-dd")+ ").xlsx" //标题
                    aLink.click()
                    document.body.appendChild(aLink)
                })
            },
            selectStandard(row){
                this.standardSelectModal = false;
                this.dataToView.companyOrgId = row.stdOrgId;
                this.dataToView.companyId = row.standardId;
                this.dataToView.companyName = row.stdOrgName;
                this.dataToView.safeRankId = row.stdRankId;
                this.dataToView.safeRank = row.stdRank;
                this.dataToView.attriErea = row.location;
                this.dataToView.safeDate = this.renderViewDate(row.appDate);

            },
            openSelect() {
                this.standardSelectModal = true
            },
            querySort({column, key, order}){
              this.pagedata.currentPage = 1;
              this.dataToQuery.order = order;
              this.dataToQuery.key = key;
              this.query1()
            },
          handleSummary({ columns, data }){
            let temp = JSON.parse(JSON.stringify(data));
            temp.splice(0, 1);
            const sums = {};
            columns.forEach((column, index) => {
              const key = column.key;
              if (index === 0) {
                sums[key] = {
                  key,
                  value: '合计'
                };
                return;
              }
              const values = temp.map(item => Number(item[key]));
              if(column.key == 'worker' || column.key == 'management'){
                if (!values.every(value => isNaN(value))) {
                  const v = values.reduce((prev, curr) => {
                    const value = Number(curr);
                    if (!isNaN(value)) {
                      return prev + curr;
                    } else {
                      return prev;
                    }
                  }, 0);
                  sums[key] = {
                    key,
                    value: v
                  };
                } else {
                  sums[key] = {
                    key,
                    value: ''
                  };
                }
              }else if(column.key == 'area'){
                if (!values.every(value => isNaN(value))) {
                  const v = values.reduce((prev, curr) => {
                    const value = Number(curr);
                    if (!isNaN(value)) {
                      return prev + curr;
                    } else {
                      return prev;
                    }
                  }, 0);
                  sums[key] = {
                    key,
                    value: v.toFixed(2)
                  };
                } else {
                  sums[key] = {
                    key,
                    value: ''
                  };
                }
              }else{
                sums[key] = {
                  key,
                  value: ''
                };
              }
            })
            return sums;
          }
        },
        watch:{

        },

    }
</script>

<style lang='css' scoped>

</style>
